script_enemy_main{

let shoot=120;
let phase=rand_int(0,1);

let shot1=0;
let bullet1=[];
let timer1=[];
let xspeed1=[];
let yspeed1=[];
let infield1=[];

let character="Nanami";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=84;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEthrow1=("\script\SoundEffects\throw1.wav");
let SEenemydeath2=("\script\SoundEffects\enemydeath2.wav");
let BG1=("\script\Images\BackgroundLayers\Nanami1.png");
let GRboss=("\script\Images\CharacterSprites\Nanami.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsNanami1.txt");

	LoadSE("\script\SoundEffects\enemydeath2.wav");
	LoadSE("\script\SoundEffects\throw1.wav");
	LoadGraphic("\script\Images\CharacterSprites\Nanami.png");
	LoadGraphic("\script\Images\BackgroundLayers\Nanami1.png");

	SetScore(2500000);
	SetLife(600);
	SetTimer(50);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);

	SetDurableSpellCard;
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,120,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ if(GetTimer>30){ damagerate=5; } if(GetTimer<=30){ damagerate=15; } }
if(GetCommonData("BombOn")==1){ damagerate=0; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Food Fight [La Tomatina]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}




if(frame==shoot && phase%2==0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,minx-32,miny+rand(60,160));
	ObjShot_SetGraphic(shot1,97);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	xspeed1=xspeed1~[shot1];
	xspeed1[length(bullet1)-1]=rand(5,7);
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-4.5,-6);
	infield1=infield1~[shot1];
	infield1[length(bullet1)-1]=0;
PlaySE(SEthrow1);
}
if(frame==shoot && phase%2!=0){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,maxx+32,miny+rand(60,160));
	ObjShot_SetGraphic(shot1,97);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	xspeed1=xspeed1~[shot1];
	xspeed1[length(bullet1)-1]=rand(-5,-7);
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=rand(-4.5,-6);
	infield1=infield1~[shot1];
	infield1[length(bullet1)-1]=0;
PlaySE(SEthrow1);
}
if(frame==shoot){ frame=0; phase++; if(shoot>=20){ shoot-=7; } }

if(time%180==0 && time>=60){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,cx+rand(-150,150),miny-32);
	ObjShot_SetGraphic(shot1,97);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	xspeed1=xspeed1~[shot1];
	xspeed1[length(bullet1)-1]=rand(-0.25,0.25);
	yspeed1=yspeed1~[shot1];
	yspeed1[length(bullet1)-1]=-1;
	infield1=infield1~[shot1];
	infield1[length(bullet1)-1]=0;
SetCommonData("WarningX",Obj_GetX(shot1));
SetCommonData("WarningY",maxy-20);
SetCommonData("WarningSide",1);
SetCommonData("WarningTime",50);
SetCommonData("WarningSize",0.75);
SetCommonData("WarningType",1);
CreateEnemyFromFile("script\Functions\warnings.txt",0,0,0,0,1);
usespell=30;
}


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); xspeed1=erase(xspeed1,i); yspeed1=erase(yspeed1,i); infield1=erase(infield1,i);
	i--;
	}
	else{
	if(Obj_GetX(bullet1[i])>=minx && Obj_GetX(bullet1[i])<=maxx && Obj_GetY(bullet1[i])>=miny){
	infield1[i]=1;
	}
	Obj_SetX(bullet1[i],Obj_GetX(bullet1[i])+xspeed1[i]);
	Obj_SetY(bullet1[i],Obj_GetY(bullet1[i])+yspeed1[i]);
		if(infield1[i]==1){
			if(Obj_GetX(bullet1[i])<=minx){
				loop(20){
				let angle=rand(-90,-30);
				CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),8*cos(angle),rand(-1,-4),-0.06*cos(angle),0.05,rand(0*cos(angle),0.3*cos(angle)),rand(3.5,4.5),25,0);
				}
			PlaySE(SEenemydeath2);
			Obj_Delete(bullet1[i]);
			}
			if(Obj_GetX(bullet1[i])>=maxx){
				loop(20){
				let angle=180+rand(-90,-30);
				CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),8*cos(angle),rand(-1,-4),-0.06*cos(angle),0.05,rand(0*cos(angle),0.3*cos(angle)),rand(3.5,4.5),25,0);
				}
			PlaySE(SEenemydeath2);
			Obj_Delete(bullet1[i]);
			}
			if(Obj_GetY(bullet1[i])>=maxy){
				loop(20){
				let angle=270+rand(-90,90);
				CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),4*cos(angle),rand(-1,-4),-0.02*cos(angle),0.07,rand(0*cos(angle),0.3*cos(angle)),rand(3.5,4.5),25,0);
				}
			PlaySE(SEenemydeath2);
			Obj_Delete(bullet1[i]);
			}
		}
	yspeed1[i]=yspeed1[i]+0.15;
	timer1[i]=timer1[i]+1;
	}
i++;
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<120){ bgfade+=5; }

	SetGraphicRect(0-time,0,588-time,588);
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(255);
	SetColor(bgfade,bgfade,bgfade);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",17); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}